package com.lanchetech.admin.controller;

import com.alibaba.fastjson.JSONObject;
import com.lanchetech.admin.aop.OperatorLog;
import com.lanchetech.admin.service.InvoiceService;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.InvoiceApplyDetailVO;
import com.lanchetech.bean.vo.InvoiceApplyVO;
import com.lanchetech.entity.InvoiceApply;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(value = "发票管理接口", tags = "发票管理接口")
@RequestMapping("/api/invoice")
@RestController
public class InvoiceController {

    @Autowired
    InvoiceService invoiceService;

    @ApiOperation("获取发票申请分页")
    @PreAuthorize("hasAuthority('order.invoice-list')")
    @PostMapping("/getInvoiceApplyPage")
    public ResultData<BasePageResp<InvoiceApplyVO>> getInvoiceApplyPage(@RequestBody PageReq req) {
        return invoiceService.getInvoiceApplyPage(req);
    }

    @ApiOperation("获取发票申请详情")
    @PreAuthorize("hasAuthority('order.invoice-list.view.auth')")
    @GetMapping("/getInvoiceApplyDetail")
    public ResultData<InvoiceApplyDetailVO> getInvoiceApplyDetail(@RequestParam("id") Long id) {
        return invoiceService.getInvoiceApplyDetail(id);
    }

    @OperatorLog("处理发票申请")
    @ApiOperation("处理发票申请")
    @PostMapping("/auditInvoiceApply")
    public BaseResp auditInvoiceApply(@RequestBody InvoiceApply invoiceApply) {
        return invoiceService.auditNuonuoInvoiceApply(invoiceApply);
    }

    @ApiOperation("刷新发票开具状态")
    @PreAuthorize("hasAuthority('order.invoice-list.view.auth')")
    @GetMapping("/refreshInvoiceResultStatus")
    public BaseResp refreshInvoiceResultStatus(@RequestParam("serialNo") String serialNo) {
        return invoiceService.refreshInvoiceResultStatus(serialNo);
    }

    @OperatorLog("重开发票申请")
    @ApiOperation("重开发票申请")
    @PreAuthorize("hasAuthority('order.invoice-list.edit.auth')")
    @GetMapping("/againInvoiceApply")
    public BaseResp againInvoiceApply(@RequestParam("serialNo") String serialNo) {
        return invoiceService.againNuonuoInvoiceApply(serialNo);
    }
}
